package com.leyou.config;

import com.leyou.api.ReceiveService;
import com.leyou.api.TurnService;
import com.leyou.domain.vo.ReceiveVO;
import com.leyou.domain.vo.TurnRecordVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * @Author lixin
 * @Date 2018/11/01 17:36
 * @Version 1.0
 * @Description 消息消费
 **/
@Component
public class RabbitReceiver {

    @Autowired
    ReceiveService receiveService;

    @Autowired
    TurnService turnService;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @RabbitHandler
    @RabbitListener(queues = "receiveQueue")
    public void process(ReceiveVO receiveVO) {


        logger.debug("消息消费receiveQueue--------" + receiveVO.toString() + new Date());

        receiveService.putReceiveRecord(receiveVO);

    }


    @RabbitHandler
    @RabbitListener(queues = "prizeQueue")
    public void process(TurnRecordVO turnRecordVO) {

        logger.debug("消息消费prizeQueue--------" + turnRecordVO.toString() + new Date());
        turnService.putTableRecord(turnRecordVO);
    }
}
